package com.project.common.caching.redis;

import com.project.common.caching.provider.ValueProvider;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

public class RedisValueProvider implements ValueProvider {
    private final ValueOperations<String, String> operations;

    public RedisValueProvider(RedisTemplate<String, String> redisTemplate) {
        this.operations = redisTemplate.opsForValue();
    }

    @Override
    public void set(String key, String value) {
        operations.set(key, value);
    }

    @Override
    public void set(String key, String value, long expiration, TimeUnit timeUnit) {
        operations.set(key, value, expiration, timeUnit);
    }

    @Override
    public void setIfAbsent(String key, String value) {
        operations.setIfAbsent(key, value);
    }

    @Override
    public void setIfAbsent(String key, String value, long expiration, TimeUnit timeUnit) {
        operations.setIfAbsent(key, value, expiration, timeUnit);
    }

    @Override
    public String get(String key) {
        return operations.get(key);
    }
}
